package com.kaka.bus.adapter;

import android.app.Activity;
import android.support.annotation.Nullable;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kaka.bus.R;
import com.kaka.bus.bean.OrderBean;
import com.kaka.bus.view.DensityUtil;

import java.util.List;

public class AmountListAdapter extends BaseQuickAdapter<OrderBean, BaseViewHolder> {
    private Activity mActivity;

    public AmountListAdapter(Activity activity, int layoutResId, @Nullable List<OrderBean> data) {
        super(layoutResId, data);
        mActivity = activity;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderBean item) {
        if (helper.getAdapterPosition() == mData.size() - 1) {
            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) helper.itemView.getLayoutParams();
            layoutParams.bottomMargin = DensityUtil.dp2px(20);
            helper.itemView.setLayoutParams(layoutParams);
        } else {
            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) helper.itemView.getLayoutParams();
            layoutParams.bottomMargin = 0;
            helper.itemView.setLayoutParams(layoutParams);
        }
        ImageView imgicon = helper.getView(R.id.img_icon);
        TextView tv_depict = helper.getView(R.id.tv_depict);
        Glide.with(mActivity).load(item.getProdIcon()).into(imgicon);
        helper.setText(R.id.tv_title, item.getProdName());
        helper.setText(R.id.tv_borrowNum, item.getBorrowNum());
        helper.setText(R.id.tv_amount, item.getAmount() + "元");
        helper.setText(R.id.tv_date, item.getEndDate());
        helper.setText(R.id.tv_status, item.getStatus());
        if (item.getProdType() != null) {
            switch (item.getProdType()) {
                case "pay_card":
                    tv_depict.setText("购物卡面额");

                    break;
                case "pay_money":
                    tv_depict.setText("借款金额");
                    break;
                default:
                    tv_depict.setText("借款金额");
            }
        }
        helper.addOnClickListener(R.id.tv_find);
    }


}
